

/**
 * 表单自定义控制器
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http) {
	$scope.bindBtn = function(event) {
		switch(event){
			case 'event-to-add': // 新增
			{
	        	var listUkey = [];
	            for(var i=0;i<$scope.subGrid.sonlist.length;i++){
	            	var data = $scope.subGrid.sonlist[i];
	            	listUkey.push(data.subCode);
	            }
	            console.log('----listUkey---', listUkey);
	            $scope.showModalCheckBox('TCG_PurchaseAppointOrderItem', 'code', listUkey);
	            break;
			}
			case 'event-to-delete': // 删除
			{
				$scope.subGrid.deleteBatch();
				var preAccount = 0;
				for (let i = 0; i < $scope.subGrid.sonlist.length; n++) {
					if($scope.subGrid.sonlist[i]['subTotalPrice']) {
						preAccount = preAccount + parseFloat($scope.subGrid.sonlist[i]['subTotalPrice']);
					}
				}
				$scope.valueMap['preAccount'] = preAccount.toFixed(2);
				break;
			}
		};
	}
}

/**
 * 子列表控制器
 */
app.controller('subGridCtrl', ['$scope', '$http', function SubGridController($scope, $http){
	//多选框回调
	$scope.checkbox.afterSelectDatas = function(rowsSelected) {
		var _list = [];
		for(var i=0;i<rowsSelected.length;i++){
			_list.push(rowsSelected[i].productCode);
		}

		var data = {productCode: _list};
		$http.post('/api/inter/tcgPurchaseAppointOrder/getProductCode', {}, {params: data})
		.success(function (res) {
			if(res.code == 0) {
				if (res.code == 0) {
					console.log('res.data---', res.data);
					for (var i = 0; i < res.data.length; i++) {
						$scope.subGrid.sonlist.push({
							subCode:res.data[i].code,
							subName:res.data[i].name,
							subBomNumber:res.data[i].num,
							subBomPrice:res.data[i].bprice,
							productCode:res.data[i].productCode,
							productName:res.data[i].productName,
							codeMerge:res.data[i].codeMerge,
							subCodeMerge:res.data[i].subCodeMerge,
						});
					}

				}
			}
		});
	}

}]);

/*
 * 自定义通用控制器，若无定义，页面会报错
 */
app.controller('formSelfCtrl', ['$scope', '$http', function FormSelfController($scope, $http){

	//单选回调
	$scope.doSelectRadioBySelf = function(data) {
		var rowCurrent = {};
		rowCurrent.id = null;
		rowCurrent.code = '保存后自动生成';
		rowCurrent.name = data.name
		rowCurrent.priceService = '0'
		rowCurrent.codeMerge = '保存后自动生成';
		rowCurrent.isSuperior = data.isSuperior;
		rowCurrent.vsfJp = data.vsfJp;
		rowCurrent.commodityProperty = '变体';
		$scope.subGrid.sonlist.push(rowCurrent);
	}
}

]);
